package com.seari.controller;

import com.seari.pojo.DevLifeCirclePojo;
import com.seari.pojo.DevPojo;
import com.seari.pojo.MessageBean;
import com.seari.pojo.StationPojo;
import com.seari.service.DevLifeService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *
 * 设备分类
 */
@Controller
@RequestMapping("dev")
public class DevLifeController {

    @Autowired
    private DevLifeService devLifeService;

    /**
     * 资材列表
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public MessageBean list(String mcIds, String keyWords, String stationId, int start , int limit){
        MessageBean message = new MessageBean("0",null,"成功");
        String[] mcList = null;
        if(mcIds!=null&&mcIds.trim().length()>0){
            mcList = mcIds.split(",");
        }

        start = (start - 1) * limit ;
        List<DevPojo> list = devLifeService.findDevList(mcList,keyWords,stationId,start,limit);
        message.setData(list);
        return message;
    }

    /**
     * 设备生命周期
     * @return
     */
    @RequestMapping("life/circle")
    @ResponseBody
    public MessageBean lifeCircle(String productId){
        MessageBean message = new MessageBean("0",null,"成功");
        List<DevLifeCirclePojo> list = devLifeService.findDevLifeCircleList(productId);
        message.setData(list);
        return message;
    }

    /**
     * 查询所有的站点
     * @return
     */
    @RequestMapping("station/list")
    @ResponseBody
    public MessageBean stationList(){
        MessageBean message = new MessageBean("0",null,"成功");
        List<StationPojo> list = devLifeService.findStationList();
        message.setData(list);
        return message;
    }
}
